<?php

namespace Ignus\View\Node\Expression;

use Ignus\View\Node\Expression;
use Ignus\View\Compiler;

class ArrayExpression extends Expression
{
    public function __construct(array $elements, $lineno)
    {
        parent::__construct($elements, array(), $lineno);
    }

    public function compile(Compiler $compiler)
    {
        $compiler->raw('array(');
        $first = true;
        foreach ($this->nodes as $name => $node) {
            if (!$first) {
                $compiler->raw(', ');
            }
            $first = false;

            $compiler
                ->repr($name)
                ->raw(' => ')
                ->subcompile($node)
            ;
        }
        $compiler->raw(')');
    }
}
